package oop5;

/**
 * @author oldliu
 * @since 1.0
 */
//宠物
public class Pet {
    protected String sex;
    private String name;
    private int health;
    private int love;

    public Pet() {

    }

    public Pet(String name, int health, int love, String sex) {
        this.name = name;
        this.health = health;
        this.love = love;
        this.sex = sex;
        System.out.println("Pet的构造方法");
    }

    public void print() {
        System.out.println("这是一个宠物");
        System.out.println("名字:" + name);
        System.out.println("健康值：" + health);
        System.out.println("可爱度：" + love);
        System.out.println("性别：" + sex);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getHealth() {
        return health;
    }

    public void setHealth(int health) {
        this.health = health;
    }

    public int getLove() {
        return love;
    }

    public void setLove(int love) {
        this.love = love;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Override
    public String toString() {
        return "宠物:name:" + name + ",健康：" + health + ",可爱度：" + this.love + ",性别：" + sex;
    }

    //定义逻辑上是否相等
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Pet) {
            Pet p = (Pet) obj;
            if (this.name.equals(p.name))
                return true;
            return false;
        }
        return false;
    }
}
